package net.ujacha.sadari.multi;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;

public class NoteFactory {

	private static Map<String, Paper> paperMap = new HashMap<String, Paper>(); 
	
	private static Note note = null;
	
	static {
		
		NoteFactory.note = new Note() {
			
			@Override
			public Paper getPaper(String id) {
				
				return paperMap.get(id);
				
			}
			
			@Override
			public String makePaper(User leader, String paperName, int maxUser, int line, boolean soloMode, boolean oneGoal) {
				
				String id = UUID.randomUUID().toString();
				
				Paper paper = new Paper(id, paperName, leader.getId(), maxUser, line, soloMode, oneGoal);
				
				paperMap.put(id, paper);
				
				return id;
			}

			@Override
			public List<Paper> listAll() {

				List<Paper> papers = new ArrayList<Paper>();
				
				
				Set<String> keys = paperMap.keySet();
				
				for(String key : keys){
				
					papers.add(paperMap.get(key));
				}
				
				return papers;
			}
		};
	};
	
	public static Note getNote(){
		return note;
	}
	
}
